﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICeFramework.DataManagement.Interfaces;
using Microsoft.SqlServer.Management.Smo;
using ICeFramework.DataManagement.Enums;

namespace ICeFramework.DataManagement.MSSql
{
    public class MSSqlServerDataType : ISqlDataType
    {
        #region public MSSqlServerDataType(SqlDataType type)
        /// <summary>
        /// Initializes a new instance of the <b>MSSqlServerDataType</b> class.
        /// </summary>
        /// <param name="type"></param>
        public MSSqlServerDataType(SqlDataType type)
        {
            switch (type)
            {
                case SqlDataType.BigInt:
                    _type = MSSqlDataTypeEnum.BigInt;
                    break;
                case SqlDataType.Binary:
                    _type = MSSqlDataTypeEnum.Binary;
                    break;
                case SqlDataType.Bit:
                    _type = MSSqlDataTypeEnum.Bit;
                    break;
                case SqlDataType.Char:
                    _type = MSSqlDataTypeEnum.Char;
                    break;
                case SqlDataType.DateTime:
                    _type = MSSqlDataTypeEnum.DateTime;
                    break;
                case SqlDataType.Decimal:
                    _type = MSSqlDataTypeEnum.Decimal;
                    break;
                case SqlDataType.Float:
                    _type = MSSqlDataTypeEnum.Float;
                    break;
                case SqlDataType.Image:
                    _type = MSSqlDataTypeEnum.Image;
                    break;
                case SqlDataType.Int:
                    _type = MSSqlDataTypeEnum.Int;
                    break;
                case SqlDataType.Money:
                    _type = MSSqlDataTypeEnum.Money;
                    break;
                case SqlDataType.NChar:
                    _type = MSSqlDataTypeEnum.NChar;
                    break;
                case SqlDataType.None:
                    _type = MSSqlDataTypeEnum.None;
                    break;
                case SqlDataType.NText:
                    _type = MSSqlDataTypeEnum.NText;
                    break;
                case SqlDataType.Numeric:
                    _type = MSSqlDataTypeEnum.Numeric;
                    break;
                case SqlDataType.NVarChar:
                    _type = MSSqlDataTypeEnum.NVarChar;
                    break;
                case SqlDataType.NVarCharMax:
                    _type = MSSqlDataTypeEnum.NVarCharMax;
                    break;
                case SqlDataType.Real:
                    _type = MSSqlDataTypeEnum.Real;
                    break;
                case SqlDataType.SmallDateTime:
                    _type = MSSqlDataTypeEnum.SmallDateTime;
                    break;
                case SqlDataType.SmallInt:
                    _type = MSSqlDataTypeEnum.SmallInt;
                    break;
                case SqlDataType.SmallMoney:
                    _type = MSSqlDataTypeEnum.SmallMoney;
                    break;
                case SqlDataType.SysName:
                    _type = MSSqlDataTypeEnum.SysName;
                    break;
                case SqlDataType.Text:
                    _type = MSSqlDataTypeEnum.Text;
                    break;
                case SqlDataType.Timestamp:
                    _type = MSSqlDataTypeEnum.Timestamp;
                    break;
                case SqlDataType.TinyInt:
                    _type = MSSqlDataTypeEnum.TinyInt;
                    break;
                case SqlDataType.UniqueIdentifier:
                    _type = MSSqlDataTypeEnum.UniqueIdentifier;
                    break;
                case SqlDataType.UserDefinedDataType:
                    _type = MSSqlDataTypeEnum.UserDefinedDataType;
                    break;
                case SqlDataType.UserDefinedType:
                    _type = MSSqlDataTypeEnum.UserDefinedType;
                    break;
                case SqlDataType.VarBinary:
                    _type = MSSqlDataTypeEnum.VarBinary;
                    break;
                case SqlDataType.VarBinaryMax:
                    _type = MSSqlDataTypeEnum.VarBinaryMax;
                    break;
                case SqlDataType.VarChar:
                    _type = MSSqlDataTypeEnum.VarChar;
                    break;
                case SqlDataType.VarCharMax:
                    _type = MSSqlDataTypeEnum.VarCharMax;
                    break;
                case SqlDataType.Variant:
                    _type = MSSqlDataTypeEnum.Variant;
                    break;
                case SqlDataType.Xml:
                    _type = MSSqlDataTypeEnum.Xml;
                    break;
                default:
                    _type = MSSqlDataTypeEnum.NotAvailable;
                    break;
            }
        }
        #endregion

        private MSSqlDataTypeEnum _type;
        #region public MSSqlDataTypeEnum Type
        /// <summary>
        /// Get/Sets the Type of the MSSqlServerDataType
        /// </summary>
        /// <value></value>
        public MSSqlDataTypeEnum Type
        {
            get { return _type; }
            set { _type = value; }
        }
        #endregion

        #region public string Name
        /// <summary>
        /// Gets the Name of the MSSqlServerDataType
        /// </summary>
        /// <value></value>
        public string Name
        {
            get { return _type.ToString(); }
        }
        #endregion

        #region public override string ToString()
        /// <summary>
        /// Returns a <see cref="string"/> that represents the current <see cref="ICeFramework.DataAccess.DataAccess.MSSql.MSSqlServerDataType"/>.
        /// </summary>
        /// <returns>A <see cref="string"/> that represents the current <see cref="ICeFramework.DataAccess.DataAccess.MSSql.MSSqlServerDataType"/>.</returns>
        public override string ToString()
        {
            return _type.ToString();
        }
        #endregion
    }
}
